#include <iostream>
#include <queue>
#include <cmath>
using namespace std;

const int N = 1e6 + 10;

int a[N],s[N],pre[N],ne[N];

struct node{
	int ch,l,r;
	bool operator < (const node& x) const{
		if(ch != x.ch) return ch > x.ch;
		else if(l != x.l) return l > x.l;
		else return r > x.r;
	}
};

priority_queue<node> heap;
bool st[N];

int main(){
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		char x;
		cin >> x;
		a[i] = (x == 'B');
		pre[i] = i - 1;
		ne[i] = i + 1;
	}
	for(int i = 1;i <= n;i++){
		cin >> s[i];
	}
	pre[1] = ne[n] = 0;
	
	for(int i = 2;i <= n;i++){
		if(a[i] != a[i - 1]){
			heap.push({abs(s[i] - s[i-1]),i - 1,i});
		}
	}
	
	vector<node> an;
	
	while(heap.size()){
		node t = heap.top();heap.pop();
		int l = t.l,r = t.r;
		
		if(st[l]||st[r]) continue;
		
		an.push_back(t);
		st[l] = st[r] = true;
		
		ne[pre[l]] = ne[r];
		pre[ne[r]] = pre[l];
		
		if(pre[l]&&ne[r]&&a[pre[l]] != a[ne[r]]) heap.push({abs(s[pre[l]]-s[ne[r]]),pre[l],ne[r]});
		
	} 
	
	cout << an.size() << endl;
	for(auto& v : an){
		cout << v.l << " " << v.r << endl; 
	}
	
	return 0;
} 
